package com.ruicar.afs.cloud.account.common.controller;

import com.ruicar.afs.cloud.account.common.service.VoucherAtomService;
import com.ruicar.afs.cloud.account.dto.atom.VoucherAtomDto;
import com.ruicar.afs.cloud.account.vo.VoucherAtomVo;
import com.ruicar.afs.cloud.common.core.log.annotation.SysLog;
import com.ruicar.afs.cloud.common.core.query.QueryCondition;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/6/23 20:34
 */
@Slf4j
@Api("凭证原子接口")
@RestController
@RequestMapping("/voucherAtom")
@AllArgsConstructor
public class VoucherAtomController {
    private final VoucherAtomService voucherAtomService;

    @PostMapping("/addVoucherAtom")
    @ApiOperation(value = "添加原子")
    @SysLog(value = "添加原子")
    public IResponse<Boolean> addAtom(@RequestBody @Validated VoucherAtomVo voucherAtomVo){
        return IResponse.success(voucherAtomService.addVoucherAtom(voucherAtomVo));
    }

    @DeleteMapping("/delVoucherAtom/{atomId}")
    @ApiOperation(value = "删除原子")
    @SysLog(value = "删除原子")
    public IResponse<Boolean> delAtom(@PathVariable String atomId){
        return IResponse.success(voucherAtomService.delVoucherAtom(atomId));
    }

    @PostMapping("/modifyVoucherAtom")
    @ApiOperation(value = "编辑原子")
    @SysLog(value = "编辑原子")
    public IResponse<Boolean> modifyAtom(@RequestBody @Validated VoucherAtomVo voucherAtomVo){
        return IResponse.success(voucherAtomService.modifyVoucherAtom(voucherAtomVo));
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询原子")
    @SysLog(value = "查询原子")
    public IResponse queryAtomList(@RequestBody QueryCondition<VoucherAtomVo> queryCondition){
        return voucherAtomService.query(queryCondition);
    }

    @PostMapping("/queryAtomsByBizType/{bizType}")
    @ApiOperation(value = "按照业务场景获取规则原子")
    public IResponse<List<VoucherAtomDto>> queryAtomsByBizType(@PathVariable String bizType){
        return voucherAtomService.queryAtomsByBizType(bizType);
    }
}
